#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/19 12:22
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : ACM.py
@Version     : Version 1.0.0
@Description : TODO 注意本实验基于Python 2.7.18 :: Anaconda, Inc.，Python3.x系列解释器不兼容，运行错误
@Created By  : PyCharm
"""
from __future__ import print_function

import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
from skimage import data
from skimage.filters import gaussian
from skimage.segmentation import active_contour
img = data.astronaut()
img = rgb2gray(img)
s = np.linspace(0, 2*np.pi, 400)
x = 220 + 100*np.cos(s)
y = 100 + 100*np.sin(s)
init = np.array([x, y]).T
snake = active_contour(gaussian(img, 3),
                       init, alpha=0.015, beta=10, gamma=0.001)
fig, ax = plt.subplots(figsize=(7, 7))
ax.imshow(img, cmap="gray")
ax.plot(init[:, 0], init[:, 1], '--r', lw=3)
ax.plot(snake[:, 0], snake[:, 1], '-b', lw=3)
ax.set_xticks([]), ax.set_yticks([])
ax.axis([0, img.shape[1], img.shape[0], 0])
plt.show()
